package com.aisino.inveli.vinda.service.impl;

import com.aisino.inveli.vinda.entity.ConfigEntity;
import com.aisino.inveli.vinda.repository.ConfigRepository;
import com.aisino.inveli.vinda.service.ConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.File;

/**
 * @author leifeng
 * @Date 2017-11-14
 **/
@Service
public class ConfigServiceImpl implements ConfigService {

    @Resource
    private ConfigRepository configRepository;

    @Override
    public void updateInputPath(String path) {
        ConfigEntity configEntity = configRepository.findOne(1);
        configEntity.setInputPath(path);
        configRepository.save(configEntity);
    }

    @Override
    public void save(ConfigEntity configEntity) {
        configRepository.save(configEntity);
    }

    @Override
    public ConfigEntity findConfigById(int i) {
        return configRepository.findOne(i);
    }

    @Override
    public void updateOutputPath(String path) {
        ConfigEntity configEntity = configRepository.findOne(1);
        configEntity.setOutputPath(path);
        configRepository.save(configEntity);
    }

    @Override
    public void updateSinglePath(File file) {
        ConfigEntity configEntity = configRepository.findOne(1);
        configEntity.setSinglePath(file.getParent());
        configEntity.setSelectPath(file.getPath());
        configRepository.save(configEntity);
    }
}
